package com.lemontree.spring4.day05web;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 * @Author: YLBG-YCY-1325
 * @Description: 加载web组件的BEAN 的配置类 相当于 spring-mvc.xml的配置
 * @Date: 2017/8/29
 */
@Configuration
@EnableWebMvc // 启用springMVC
@ComponentScan(basePackages = "com.lemontree.spring4.day05web")
public class WebConfig extends WebMvcConfigurerAdapter {

    /**
     * 视图的处理
     * @return
     */
    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setSuffix("/WEB-INF/views/");
        viewResolver.setPrefix(".jsp");
        viewResolver.setExposeContextBeansAsAttributes(true);
        return viewResolver;
    }

    /**
     * 匹配静态资源的处理
     * @param configurer
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
}
